import { Platform, NativeModules} from 'react-native'
import { Lt } from "./Jx"

// 从原生获取信息
export const Build = {
    NONE : -1,
    DEBUG : 0,
    RELEASE : 1,
    type : -1,
    versionName : "",
    versionDesc : "",
    desc : "",
    appid : "",
    secret : "",
    appkey : "",
}

export function promiseBuild(){
    if(Build.type != Build.NONE){
        return Promise.resolve(Build);
    }
    return new Promise((resolve, reject)=>{
        let m = NativeModules.uModules;
        Promise.all([
            // 获取 debug/release模式 
            m.getBuildType(),
            // 获取 app版本
            m.getVersionName(),
            // 获取热更新 key
            // await m.getCodePushKey(),
        ]).then(rs=>{
            Build.type = rs[0];
            Build.versionName = rs[1];
            // Build.codePushKey = rs[2];
            Build.desc = ["debug", "release"][Build.type];
            Build.versionDesc = Build.versionName + (["调试版"][Build.type]);
            // 微信appid
            Build.appid = "";
            // 微信 app secret
            Build.secret = "";
            Build.desc =  
                Build.versionName + "\n" + 
                Build.desc + "\n" + 
                Platform.OS + "\n" + 
                Lt.width + "," + Lt.height
            // 冻结, 不允许修改
            Object.freeze(Build);
            resolve(Build);
        }).catch(err=>reject(err));
    })
}
